package com.ThreadExHandler;

/**
 * @author Zhang Guangyong
 * @desacription 线程异常处理器
 * @date 2019年08月20日 11:31
 */
class MyExHandler implements Thread.UncaughtExceptionHandler {

    /**
     * Method invoked when the given thread terminates due to the
     * given uncaught exception.
     * <p>Any exception thrown by this method will be ignored by the
     * Java Virtual Machine.
     *
     * @param t the thread
     * @param e the exception
     */
    @Override
    public void uncaughtException(Thread t, Throwable e) {
        System.out.println(t + "线程出现了异常:" + e);
        System.out.println("呵呵呵呵呵呵呵呵呵");
    }
}



public class ExHandler {

    public static void main(String[] args) {

        Thread.currentThread().setUncaughtExceptionHandler(new MyExHandler());

        int a = 5 / 0;

        System.out.println("结束");


    }
}
